Setting Paradox master password


At design time you can set a password for a paradox table using Database Desktop
tool. At run-time you can set the password using direct BDE API functions. Below
procedure can set a master password for Paradox tables, but you have to include BDE,
DB, and DBTables in uses clause:


procedure AddMasterPassword(Table: TTable; pswd: string);
const
RESTRUCTURE_TRUE = WordBool(1);

var
TblDesc: CRTblDesc;
hDb: hDBIDb;

begin
 { Make sure that the table is opened and is exclusive }
 if (Table.Active = False) or (Table.Exclusive = False) then
  raise EDatabaseError.Create('Table must be opened in exclusive mode to add passwords');
 { Initialize the table descriptor }
 FillChar(TblDesc, SizeOf(CRTblDesc), 0);

with TblDesc do
begin
   { Place the table name in descriptor }
   StrPCopy(szTblName, Table.TableName);
   { Place the table type in descriptor }
   StrCopy(szTblType, szPARADOX);
   { Master Password, Password }
   StrPCopy(szPassword, pswd);
   { Set bProtected to True }
   bProtected := RESTRUCTURE_TRUE;
end;

 { Get the database handle from the cursor handle }
 Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
 { Close the table }
 Table.Close;
 { Add the master password to the Paradox table }
 Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, FALSE));
 { Add the new password to the session }
 Session.AddPassword(pswd);
 { Re-Open the table }
 Table.Open;
end;


Example of calling password procedure

- Drop a Table.
- Set table's DatabaseName to any Alias and TableName to any Paradox table.
- Add
bde to Unit1 uses section and make sure that DBTables and Db also added to
uses section.

- Copy and paste above procedure in
Unit1.
- Drop a button.
- At button's
OnClick event write:

 Table1.Close;
Table1.Exclusive:= True;
Table1.Open;
 AddMasterPassword(Table1, 'test');


Notes:

- Befor setting password you have to make sure that the table is opened in exclusive
mode.

- Password is case sensitive.

See also

Removing Paradox master password